
import { Injector } from "./app_base/base/utils/Injector";
import { NativeHelper } from "./app_base/module/native/NativeHelper";
import { Timer } from "./app_base/module/timer/Timer";
import { StorageUtils } from "./app_base/module/utils/StorageUtils";
import { ViewManager } from "./app_base/module/view/ViewManager";
import { app } from "./base";
import { CocosStorageUtils } from "./data/CocosStorageUtils";
import { CocosNativeHelper } from "./app_cocos/native/CocosNativeHelper";
import { TimerImpl } from "./app_cocos/tick/TickManagerImpl";
import { CocosViewManager } from "./app_cocos/View/CocosViewManager";
import { Application, IApplication } from "./app_base/base/Application";

/**
 * 框架类，处理框架启动等逻辑
 */
export class CocosApp implements IApplication {

    launch(): void {
        this._injects();
        this._setVolume();
    }

    private _injects() {
        Injector.inject(StorageUtils.KEY, CocosStorageUtils);
        Injector.inject(Timer.KEY, TimerImpl);
        Injector.inject(NativeHelper.KEY, CocosNativeHelper);
        Injector.inject(ViewManager.KEY, CocosViewManager);
    }

    private _setVolume(): void {
        cc.audioEngine.setMusicVolume(app.storage.musicVolume);
        cc.audioEngine.setEffectsVolume(app.storage.effectsVolume);
    }

    onShow(call: () => void, caller?: any): void {
        cc.game.on(cc.game.EVENT_SHOW, call, caller);
    }

    offShow(call: () => void, caller?: any): void {
        cc.game.off(cc.game.EVENT_SHOW, call, caller);
    }

    onHide(call: () => void, caller?: any): void {
        cc.game.on(cc.game.EVENT_HIDE, call, caller);
    }

    offHide(call: () => void, caller?: any): void {
        cc.game.off(cc.game.EVENT_HIDE, call, caller);
    }
}

Injector.inject(Application.KEY, CocosApp);